package com.xzs.data.controller;


import com.alibaba.fastjson.JSONObject;
import com.xzs.data.util.HttpUtil;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
public class RPCSDateContrlller {

    private List<String> openids = new ArrayList<>();

    @RequestMapping(value = "/inviteCode", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
    public String inviteCode(@RequestBody Map<String, Object> param) {

        //2 获取session_key
        String openid = refreshSession((String) param.get("jsCode"));
        System.out.println(openid);
        openids.add(openid);
        return "{\"code\":\"200\",\"msg\":\"chengg\",\"data\":\"" + openid + "\"}";
    }

    @RequestMapping(value = "/userLogin", method = RequestMethod.POST)
    public String userLogin(@RequestBody Map<String, Object> param) {
        System.out.println(param.toString());
        String openid = refreshSession((String) param.get("jsCode"));
        String sf = "";
        if ("omlfd4hEbgKH_UaJz5lEYac3WFBI".equals(openid)) {
            sf = "服务中心用户";
//            sf= "未分配";
        } else if ("omlfd4hgTzp2QZl2B_rNgi5hZ5JE".equals(openid)) {
            sf = "未分配";
            sf = "服务中心用户";
        } else if ("omlfd4rRexVhdiJY1akC0v9DRLdw".equals(openid)) {
            sf = "司局管理员";
        } else {
            sf = "查岗员";
        }
//        if(!openids.contains(openid)){
//            return "{\"code\":\"500\",\"msg\":\"查询失败\",\"data\":null}";
//        }
        return "{\"code\":\"200\",\"msg\":\"查询成功\",\"data\":{\"userRole\":\"" + sf + "\",\"openID\":\"" + openid + "\"}}";
    }

    @RequestMapping(value = "/fillUserInfo", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
    public String fillUserInfo(@RequestBody Map<String, Object> param) {
        System.out.println(param.toString());
        return "{\"code\":\"200\",\"msg\":\"chengg\",\"data\":\"修改用户信息成功\"}";
    }


    @RequestMapping(value = "/reimbursement/listReimbursementByUserId", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
    public String listReimbursementByUserId() {
//        System.out.println(param.toString());
        return "{\"resultCode\":\"0000\",\"message\":\"成功\",\"data\":[{\"currentPage\":1,\"pageSize\":5,\"totalCount\":7,\"totalPage\":2,\"list\":[{\"id\":\"c54b4debae87475abc944b4cbbb5042e\",\"companyId\":\"agencyId5\",\"companyName\":\"C中台随机模拟单位5\",\"userId\":\"e97a95b563af40a3abbbb9eda6ef41d4\",\"remark\":\"\",\"bankName\":\"\",\"bankCardNo\":\"1234567890\",\"invoiceCount\":0,\"totalAmount\":0,\"auditStatus\":\"0\",\"auditMessage\":null,\"createDateTime\":\"2019-12-24\",\"auditDateTime\":\"2019-12-24\"}],\"startRow\":0,\"endRow\":5}]}";
    }


    @RequestMapping(value = "/userInfo", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public String userInfo(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"chengg\",\"data\":{\"uname\":\"张三\",\"dept\":\"司局\",\"cardNum\":\"123456\",\"phoneNum\":\"18233138097\",\"tellPhone\":\"010-22222222\",\"emailAdd\":\"123123414@qq.com\",\"account\":\"zhanghao\",\"pwd\":\"管理端密码11\"，\"spflag\"：\"1\"}}";
    }

    @RequestMapping(value = "/getNoticeList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public String getNoticeList(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"chengg\",\"data\":[]}";
    }

    @RequestMapping(value = "/getNotice", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public String getNotice(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"chengg\",\"data\":\"老楼11:00-11:20取餐，新楼11：20-11:40取餐，事业单位11:40-12:00取餐。 \"}";
    }

    @RequestMapping(value = "/healthyInfo", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
    public String healthyInfo(@RequestBody Map<String, Object> param) {
        System.out.println(param.toString());
        return "{\"code\":\"200\",\"msg\":\"chengg\",\"data\":\"baocheng\"}";
    }

    @RequestMapping(value = "/goBackInfo", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
    public String goBackInfo(@RequestBody Map<String, Object> param) {
        System.out.println(param.toString());
        return "{\"code\":\"200\",\"msg\":\"chengg\",\"data\":\"保存成功\"}";
    }

    @RequestMapping(value = "/ordering", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
    public String ordering(@RequestBody Map<String, Object> param) {
        System.out.println(param.toString());
        return "{\"code\":\"200\",\"msg\":\"成功\",\"data\":\"订餐成功\"}";
    }


    @RequestMapping(value = "/orderingTotal", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public String orderingTotal(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"成功\",\"data\":{\"total\":{\"breakfast\":\"总数\",\"lunch\":\"总数\",\"supper\":\"总数\"},\"takedTotal\":{\"breakfast\":\"总数\",\"lunch\":\"总数\",\"supper\":\"总数\"}}}";
    }

    @RequestMapping(value = "/orderingDetail", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public String orderingDetail(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"成功\",\"data\":[{\"uname\":\"用户名\",\"cardNum\":\"餐卡\",\"breakfast\":\"1\",\"lunch\":\"1\",\"supper\":\"1\"},{\"uname\":\"张三\",\"cardNum\":\"123\",\"breakfast\":\"1\",\"lunch\":\"1\",\"supper\":\"1\"}]}";
    }

    @RequestMapping(value = "/findOrdering", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public String findOrdering(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"查询成本\",\"data\":{\"orderTime\":\"订单时间\",\"orderId\":\"订单ID\",\"orders\":[{\"itemID\":\"订单条目ID\",\"type\":\"0\",\"isMuslim\":\"0\",\"status\":\"0\"},{\"itemID\":\"订单条目ID\",\"type\":\"1\",\"isMuslim\":\"1\",\"status\":\"1\"},{\"itemID\":\"订单条目ID\",\"type\":\"2\",\"isMuslim\":\"0\",\"status\":\"2\"}]}}";
    }

    @RequestMapping(value = "/takeMealList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public String takeMealList(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"查询成本\",\"data\":{\"breakfast\":[{\"fid\":\"1\",\"status\":\"1\",\"deptName\":\"司局1\",\"num\":\"20\",\"muslimCount\":\"2\"},{\"fid\":\"2\",\"status\":\"0\",\"deptName\":\"司局2\",\"num\":\"40\",\"muslimCount\":\"0\"}],\"lunch\":[{\"fid\":\"2\",\"status\":\"1\",\"deptName\":\"司局1\",\"num\":\"12\",\"muslimCount\":\"1\"},{\"fid\":\"3\",\"status\":\"0\",\"deptName\":\"司局2\",\"num\":\"50\",\"muslimCount\":\"10\"}],\"supper\":[{\"fid\":\"5\",\"status\":\"1\",\"deptName\":\"司局1\",\"num\":\"8\",\"muslimCount\":\"1\"},{\"fid\":\"6\",\"status\":\"0\",\"deptName\":\"司局2\",\"num\":\"30\",\"muslimCount\":\"3\"}],\"breakfastTotal\":\"30\",\"breakfastMuslimTotal\":\"10\",\"lunchTotal\":\"60\",\"lunchMuslimTotal\":\"20\",\"supperTotal\":\"40\",\"supperMuslimTotal\":\"19\",\"totalNum\":\"100000\"}}";
    }


    @RequestMapping(value = "/takeMeals", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
    public String takeMeals(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"chengg\",\"data\":\"取餐登记成功\"}";
    }

    @RequestMapping(value = "/deptOrderReport", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public String deptOrderReport(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"chengg\",\"data\":{\"breakfast\":\"999\",\"lunch\":\"1\",\"supper\":\"2\",\"breakfastMuslim\":\"111\",\"lunchMuslim\":\"1\",\"supperMuslim\":\"1\",\"takedBreakfast\":\"1\",\"takedLunch\":\"1\",\"takedSupper\":\"1\",\"takedBreakfastMuslim\":\"1\",\"takedLunchMuslim\":\"1\",\"takedSupperMuslim\":\"1\",\"officeList\":[{\"code\":\"2312\",\"name\":\"宝宝宝宝宝宝宝宝宝宝宝宝\",\"breakfast\":\"99\",\"lunch\":\"12\",\"supper\":\"12\",\"breakfastMuslim\":\"88\",\"lunchMuslim\":\"12\",\"supperMuslim\":\"12\",\"list\":[{\"uname\":\"抱抱\",\"cardNum\":\"123\",\"breakfast\":\"1\",\"lunch\":\"1\",\"supper\":\"1\",\"breakfastStatus\":\"1\",\"lunchStatus\":\"1\",\"suppeStatus\":\"0\",\"breakfastMuslim\":\"1\",\"lunchMuslim\":\"0\",\"supperMuslim\":\"1\"},{\"uname\":\"抱抱\",\"cardNum\":\"123\",\"breakfast\":\"1\",\"lunch\":\"1\",\"supper\":\"1\",\"breakfastStatus\":\"0\",\"lunchStatus\":\"1\",\"suppeStatus\":\"0\",\"breakfastMuslim\":\"是\",\"lunchMuslim\":\"否\",\"supperMuslim\":\"是\"}]},{\"code\":\"2312\",\"name\":\"宝宝\",\"breakfast\":\"12\",\"lunch\":\"12\",\"supper\":\"12\",\"breakfastMuslim\":\"12\",\"lunchMuslim\":\"12\",\"supperMuslim\":\"12\",\"list\":[{\"uname\":\"抱抱\",\"cardNum\":\"123\",\"breakfast\":\"1\",\"lunch\":\"1\",\"supper\":\"1\",\"breakfastStatus\":\"0\",\"lunchStatus\":\"1\",\"suppeStatus\":\"0\",\"breakfastMuslim\":\"是\",\"lunchMuslim\":\"否\",\"supperMuslim\":\"是\"},{\"uname\":\"抱抱\",\"cardNum\":\"123\",\"breakfast\":\"1\",\"lunch\":\"1\",\"supper\":\"1\",\"breakfastStatus\":\"0\",\"lunchStatus\":\"1\",\"suppeStatus\":\"0\",\"breakfastMuslim\":\"是\",\"lunchMuslim\":\"否\",\"supperMuslim\":\"是\"}]}]}}";
    }

    @RequestMapping(value = "/foodOrderReport", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public String foodOrderReport(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"成功\",\"data\":{\"totalAmountB1\":\"0\",\"totalAmountB2\":\"0\",\"totalAmountA1\":\"4\",\"totalAmountA2\":\"5\",\"totalB1\":\"23\",\"deptList\":[{\"code\":\"司局编码\",\"name\":\"司局名称\",\"totalA1\":3,\"totalA2\":4,\"totalB1\":\"1\",\"totalB2\":6,\"officeList\":[{\"code\":\"123\",\"name\":\" 处室名称\",\"totalA1\":\"1\",\"totalA2\":\"1\",\"totalB1\":\"1\",\"totalB2\":\"1\"}]}]}}";
    }

    @RequestMapping(value = "/displayInvoice/blockChainInfo", produces = MediaType.APPLICATION_JSON_VALUE)
    public String blockChainInfo(String wxCode) {
        System.out.println(wxCode);
        return "{\"resultCode\":\"0000\",\"message\":\"成功\",\"data\":[{\"infoList\":[{\"name\":\"交易时间\",\"value\":\"2020-04-19 19:40:41\"},{\"name\":\"交易哈希\",\"value\":\"123412412341234\"},{\"name\":\"单位\",\"value\":\"test\"}],\"txDate\":\"2020-04-19 19:40:41\",\"txName\":\"开具\",\"txType\":\"1\"},{\"infoList\":[{\"name\":\"交易时间\",\"value\":\"2020-04-19 19:40:41\"},{\"name\":\"交易哈希\",\"value\":\"123412412341234\"},{\"name\":\"转让方\",\"value\":\"索隆\"},{\"name\":\"被转让方\",\"value\":\"路飞\"}],\"txDate\":\"2020-04-19 19:40:41\",\"txName\":\"转让\",\"txType\":\"2\"}]}";
    }

    @RequestMapping(value = "/getArriveSituationHomePageInfo", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getArriveSituationHomePageInfo(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"成功\",\"data\":{\"officeFormalStaffArriveNum\":\"12\",\"officeTempStaffArriveNum\":\"12\",\"deptFormalStaffArriveNum\":\"12\",\"deptTempStaffArriveNum\":\"12\"}}";
    }

    @RequestMapping(value = "/getArriveSituationOfficeInfo", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getArriveSituationOfficeInfo(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"成功\",\"data\":{\"formalStaff\":{\"formalTotal\":\"13\",\"users\":[\"张三\",\"李四\",\"哈麦提尼古拉斯\",\"蒙奇D路飞\",\"乔巴\",\"乌索普\",\"索隆\",\"娜美\",\"布鲁克\",\"罗宾\",\"艾斯\"]},\"tempStaff\":{\"tempTotal\":\"24\",\"details\":[{\"agenName\":\"公司名称\",\"agenTotal\":\"公司总人数\",\"users\":[\"蒙奇·D·龙\",\"香克斯\",\"朱诺基尔·米霍克\",\"波雅·汉库克\",\"甚平\",\"沙·克洛克达尔\",\"青雉\",\"蒙奇·D·卡普\",\"弗兰奇\",\"山治\"]},{\"agenName\":\"公司名称\",\"agenTotal\":\"公司总人数\",\"users\":[\"蒙奇·D·龙\",\"香克斯\",\"朱诺基尔·米霍克\",\"波雅·汉库克\",\"甚平\",\"沙·克洛克达尔\",\"青雉\",\"蒙奇·D·卡普\",\"弗兰奇\",\"山治\"]}]}}}";
    }

    @RequestMapping(value = "/getArriveSituationDeptInfo", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getArriveSituationDeptInfo(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"成功\",\"data\":[{\"officeName\":\"处室名称\",\"officeTotal\":\"22\",\"formalStaff\":{\"formalTotal\":\"31\",\"users\":[\"张三\",\"李四\",\"王五\",\"张三1\",\"张三2\",\"张三3\",\"张三4\",\"张三5\",\"张三6\",\"张三7\"]},\"tempStaff\":{\"tempTotal\":\"42\",\"details\":[{\"agenName\":\"公司名称\",\"agenTotal\":\"66\",\"users\":[\"张三\",\"李四\",\"王五\",\"张三1\",\"张三2\",\"张三3\",\"张三4\",\"张三5\",\"张三6\",\"张三7\"]},{\"agenName\":\"公司名称3\",\"agenTotal\":\"44\",\"users\":[\"张三\",\"李四\",\"王五\",\"张三1\",\"张三2\",\"张三3\",\"张三4\",\"张三5\",\"张三6\",\"张三7\"]}]}},{\"officeName\":\"处室名称2\",\"officeTotal\":\"52\",\"formalStaff\":{\"formalTotal\":\"12\",\"users\":[\"张三\",\"李四\",\"王五\",\"张三1\",\"张三2\",\"张三3\",\"张三4\",\"张三5\",\"张三6\",\"张三7\"]},\"tempStaff\":{\"tempTotal\":\"22\",\"details\":[{\"agenName\":\"公司名称2\",\"agenTotal\":\"12\",\"users\":[\"张三\",\"李四\",\"王五\",\"张三1\",\"张三2\",\"张三3\",\"张三4\",\"张三5\",\"张三6\",\"张三7\"]},{\"agenName\":\"公司名称4\",\"agenTotal\":\"11\",\"users\":[\"张三\",\"李四\",\"王五\",\"张三1\",\"张三2\",\"张三3\",\"张三4\",\"张三5\",\"张三6\",\"张三7\"]}]}}]}";
    }

    @RequestMapping(value = "/getArriveSituationRegisterInfo", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getArriveSituationRegisterInfo(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"成功\",\"data\":{\"formalStaff\":{\"formalTotal\":\"22\",\"users\":[{\"name\":\"姓名\",\"wxcode\":\"12344\",\"status\":\"1\"},{\"name\":\"姓名2\",\"wxcode\":\"123447\",\"status\":\"0\"}]},\"tempStaff\":{\"tempTotal\":\"驻场总人数\",\"details\":[{\"agenName\":\"公司名称\",\"agenTotal\":\"34\",\"users\":[{\"name\":\"姓名3\",\"wxcode\":\"123\",\"status\":\"1\"},{\"name\":\"姓名4\",\"wxcode\":\"12378\",\"status\":\"0\"}]},{\"agenName\":\"公司名称1\",\"agenTotal\":\"123\",\"users\":[{\"name\":\"姓名45\",\"wxcode\":\"123\",\"status\":\"1\"},{\"name\":\"姓名55\",\"wxcode\":\"12378\",\"status\":\"0\"}]}]}}}";
    }

    @RequestMapping(value = "/setArriveSituationRegisterInfo", produces = MediaType.APPLICATION_JSON_VALUE)
    public String setArriveSituationRegisterInfo(String wxCode) {
        System.out.println(wxCode);
        return "{\"code\":\"200\",\"msg\":\"chengg\",\"data\":\"提交成功\"}";
    }

    public String refreshSession(String js_code) {
        String url = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code";
        url = url.replaceAll("APPID", "wx573d8813daffb6e7").replace("SECRET", "e471faf8ebc79ec08df616c5bab7a61d").replace("JSCODE", js_code);

        JSONObject jsonObject = HttpUtil.httpsRequest(url, "GET", null);

        return jsonObject.getString("openid");
    }

}
